package com.csun.cmny.provider.controller.rpc;

import com.csun.cmny.provider.model.domain.UacStaff;
import com.csun.cmny.provider.model.service.UacMerchantFeignApi;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.UacFirstLvelMerchantBindService;
import com.csun.cmny.provider.service.UacMerchantService;
import com.csun.cmny.provider.service.UacStaffService;
import com.csun.cmny.util.PublicUtil;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@Api(value = "API - UacMerchantFeignClient", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UacMerchantFeignClient implements UacMerchantFeignApi {

    @Resource
    private UacMerchantService uacMerchantService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private UacFirstLvelMerchantBindService uacFirstLvelMerchantBindService;
    @Resource
    private UacStaffService staffService;

    @Override
    public Wrapper<Integer> checkMerchantOnline(@RequestParam("merchantId") Long merchantId) {
        int i = uacMerchantService.checkMerchantOnline(merchantId);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), i);
    }

    @Override
    public Wrapper<Integer> checkServiceFirstLevelUsed(@RequestParam("firstLevelId") Long firstLevelId) {
        int i = uacFirstLvelMerchantBindService.checkServiceFirstLevelUsed(firstLevelId);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), i);
    }

    @Override
    public Wrapper<Integer> countStaff(Long staffId) {



        UacStaff staff = staffService.selectByKey(staffId);
        if (PublicUtil.isNotEmpty(staff)){
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                    .getMessage("operation.success", null), 1);
        }
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), 0);
    }
}
